﻿using BillUpload.Model;
using System;
using System.Collections.Generic;

namespace BillUpload.Util
{
    class BillUtil
    {
        private static Dictionary<String, String> dictTitle = new Dictionary<String, String>() {
            {"门店id", "platShopId"},
            {"门店名称", "platShopName"},
            {"账单日期", "billDate"},
            {"账单金额", "checkoutAmount"},
            {"结算状态", "status"}
        };

        private static Dictionary<String, String> dictData = new Dictionary<String, String>();

        public static bool IsReserve(String ColumnName, String ColumnVal)
        {

            if (dictTitle.ContainsKey(ColumnVal))
            {
                Console.WriteLine(ColumnVal);
                if (!dictData.ContainsKey(ColumnName))
                    dictData.Add(ColumnName, dictTitle[ColumnVal]);
                return true;
            }
            return false;
        }

        public static void FillData(Bill bill, String ColumnName, String ColumnVal)
        {
            if (dictData.ContainsKey(ColumnName))
            {

                switch (dictData[ColumnName])
                {
                    case "platShopId":
                        bill.platShopId = ColumnVal;
                        break;
                    case "platShopName":
                        bill.platShopName = ColumnVal;
                        break;
                    case "billDate":
                        String billDate = DateUtil.ParsedAndPlus(ColumnVal);
                        bill.billDate = billDate;
                        bill.checkoutDate = billDate;
                        break;
                    case "checkoutAmount":
                        bill.checkoutAmount = Double.Parse(ColumnVal);
                        bill.transferAmount = bill.checkoutAmount;
                        break;
                    case "status":
                        bill.status = ColumnVal.Equals("已结算") ? 2 : 1;
                        break;
                }
            }
        }
    }
}
